/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ssp.strategy.agent.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import ssp.ResourceManager;
import ssp.SimulationManager;
import ssp.net.NWcomponent;

/**
 * シミュレーション中のトポロジにおける経路情報を保持するクラス
 * @author yamazaki
 */
public final class PathTable implements ResourceManager {
    
    private static PathTable INSTANCE = new PathTable();
    
    private Map<LinkedList<NWcomponent>, List<Double>> path;
    
    private PathTable() {
        init();
        SimulationManager.register(this);
    }

    @Override
    public final void init() {
        this.path = new HashMap<>();
    }
    
    public static PathTable getINSTANCE() {
        return INSTANCE;
    }
    
    public void addPath(LinkedList<NWcomponent> nwComponents, List<Double> qos) {
        this.path.put(nwComponents, qos);
    }
    
    public Map<List<NWcomponent>, List<Double>> getPath(int srcNodeID, int dstNodeID) {
        Map<List<NWcomponent>, List<Double>> result = new HashMap<>();
        for(Entry<LinkedList<NWcomponent>, List<Double>> entry : path.entrySet()) {
            if(entry.getKey().getFirst().getID() == srcNodeID && entry.getKey().getLast().getID() == dstNodeID) {
                result.put(new ArrayList<>(entry.getKey()), new ArrayList<>(entry.getValue()));
            }
        }
        return result;
    }
    
}
